package cn.mazexal.exambg.controller.common;

import cn.mazexal.exambg.common.models.SingleResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @author: Mazexal
 * Date: 2023/6/2
 */
@RestControllerAdvice
@Slf4j
@RestController
public class GlobalExceptionHandler {

    @ResponseBody
    @ExceptionHandler(value = Exception.class)
    public SingleResponse handleException(Exception e) {
        log.error("Exception: {}", e);
        return SingleResponse.error("500",e.getMessage());
    }
}
